package com.coda.service.impl;

import com.coda.adminVo.agreement.AgreementVo;
import com.coda.adminVo.appointment.AppointmentQueryVo;
import com.coda.adminVo.appointment.AppointmentVo;
import com.coda.entity.*;
import com.coda.mapper.*;
import com.coda.result.PageResult;
import com.coda.service.ViewAppointmentService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.google.j2objc.annotations.AutoreleasePool;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ViewAppointmentServiceImpl implements ViewAppointmentService {
    @Autowired
    private ViewAppointmentMapper viewAppointmentMapper;
    @Autowired
    private ApartmentMapper apartmentMapper;


    /**
     * 条件分页查询预约信息
     *
     * @return
     */
    @Override
    public PageResult getPageList(Integer current, Integer size, AppointmentQueryVo appointmentQueryVo) {
        //设置分页参数
        PageHelper.startPage(current, size);
        //查找租约信息
        Page<AppointmentVo> appointmentQueryVos = viewAppointmentMapper.getPageList(appointmentQueryVo);
        //查找租约对应的公寓
        for (AppointmentVo queryVo : appointmentQueryVos) {
            ApartmentInfo apartment = apartmentMapper.getApartment(queryVo.getApartmentId());
            queryVo.setApartmentInfo(apartment);
        }

        PageResult pageResult = new PageResult(appointmentQueryVos.getTotal(),appointmentQueryVos.getResult());
        return pageResult;
    }

    /**
     * 根据id更新预约状态
     * @param id
     * @param status
     */
    @Override
    public void updateStatusById(Long id, Integer status) {
        ViewAppointment viewAppointment = new ViewAppointment();
        viewAppointment.setId(id);
        viewAppointment.setAppointmentStatus(status);
        viewAppointmentMapper.updateStatus(viewAppointment);
    }


}
